package leecode;

import java.security.Key;

/**
 * 删除有序数组重复项
 *
 * @author qingyan 2021-08-18
 */
public class Question26 {

    public int removeDuplicates(int[] nums) {
        // 111222233345666777888

        // 111222233345666788877
        // 111222233345668788677
        if (nums.length < 2) {
            return nums.length;
        }

        int i = 1, j = 1;
        for (;j < nums.length; j++) {
            if (nums[i - 1] != nums[j]) {
                nums[i++] = nums[j];
            }
        }
        return i;
    }

    public static void main(String[] args) {
        Question26 q26 = new Question26();
        int[] nums = {1,2,3,3,4};
        int num = q26.removeDuplicates(nums);
        for (int j = 0; j < num; j++) {
            System.out.println(nums[j]);
        }
    }
}
